package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"math/rand"
	"time"
	"user-reg-mgr/cache"
	"user-reg-mgr/goods/goods"
	"user-reg-mgr/goods/internal/svc"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *goods.SendSmsRequest) (*goods.SendSmsResponse, error) {
	// todo: add your logic here and delete this line
	code := rand.Intn(9000) + 1000
	/*
		sms, err := pkg.Init(in.Mobile, strconv.Itoa(code))
			if err != nil {
				return nil, err
			}
			if sms.Code != 2 {
				return nil, errors.New(sms.Msg)
			}
	*/

	cache.Rdb.Set(l.ctx, "SendSms"+in.Mobile, code, time.Minute*3)
	return &goods.SendSmsResponse{}, nil
}
